Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a race in temp file creation. #565

Merged
merged 1 commit into from
Oct 6, 2020

Conversation

aalexand
Copy link
Collaborator

@aalexand aalexand commented Oct 4, 2020

The added test fails before the fix and passes after.

Fixes #500.

@google-cla google-cla bot added the cla: yes label Oct 4, 2020
@aalexand aalexand requested a review from kalyanac October 4, 2020 01:31
@aalexand aalexand force-pushed the no-race-tempfile branch 2 times, most recently from 13f5fc0 to 2c1365a Compare October 4, 2020 01:53
@codecov-commenter
Copy link

codecov-commenter commented Oct 4, 2020

Codecov Report

Merging #565 into master will increase coverage by 0.02%.
The diff coverage is 60.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #565      +/-   ##
==========================================
+ Coverage   67.12%   67.14%   +0.02%     
==========================================
  Files          78       78              
  Lines       14062    14072      +10     
==========================================
+ Hits         9439     9449      +10     
+ Misses       3790     3788       -2     
- Partials      833      835       +2     
Impacted Files Coverage Δ
internal/driver/tempfile.go 68.75% <60.00%> (+14.20%) ⬆️
...ithub.com/google/pprof/internal/driver/tempfile.go 68.75% <0.00%> (+14.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c5bbb0...a13cf9d. Read the comment docs.

@aalexand aalexand requested a review from nolanmar511 October 5, 2020 02:19
nolanmar511
nolanmar511 previously approved these changes Oct 5, 2020
if !os.IsNotExist(err) {
return nil, err
}
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think Stat() is needed. Just call OpenFile with os.O_RDWR|os.O_CREATE|os.O_EXCL directly and handle err as needed. If this is racy, checking Stat() prior to OpenFile does not guarantee success in all cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I thought about this and left the os.Stat() call to avoid spurious write accesses - somehow it felt better to only probe with a read rather than with a write. But it shouldn't matter as far as I can think of it, and less code is good.

The added test fails before the fix and passes after.

Fixes google#500.
@aalexand aalexand merged commit 29d1258 into google:master Oct 6, 2020
@aalexand aalexand deleted the no-race-tempfile branch October 6, 2020 06:14
giordano added a commit to JuliaPackaging/Yggdrasil that referenced this pull request Nov 13, 2020
* Update pprof to latest revision

Bump from 20191205061153 => 20201109224723

My personal interest is to pull in google/pprof#564, which adds support for displaying names with `"` in them, which julia functions sometimes have (e.g. `var"#foo#23"`)

Includes:
- google/pprof#564
- google/pprof#575
- google/pprof#574
- google/pprof#571
- google/pprof#572
- google/pprof#570
- google/pprof#562
- google/pprof#561
- google/pprof#565
- google/pprof#560
- google/pprof#563
- google/pprof#557
- google/pprof#554
- google/pprof#552
- google/pprof#545
- google/pprof#549
- google/pprof#547
- google/pprof#541
- google/pprof#534
- google/pprof#542
- google/pprof#535
- google/pprof#531
- google/pprof#530
- google/pprof#528
- google/pprof#522
- google/pprof#525
- google/pprof#527
- google/pprof#519
- google/pprof#520
- google/pprof#517
- google/pprof#518
- google/pprof#514
- google/pprof#513
- google/pprof#510
- google/pprof#508
- google/pprof#506
- google/pprof#509
- google/pprof#504

* Update P/pprof/build_tarballs.jl - use a real version number

Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>

* Remove now unused `timestamp`

* [pprof] Use `GitSource`

Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
gmarin13 pushed a commit to gmarin13/pprof that referenced this pull request Dec 17, 2020
The added test fails before the fix and passes after.

Fixes google#500.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants